package com.bms.controller;

import com.alibaba.fastjson.JSON;
import com.bms.Dao.UserDao;
import com.bms.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class Login {

    @Autowired
    UserDao userDao;

    @RequestMapping("/login")
   public String  login(@RequestBody User user){
        int code=60204;
        System.out.println("前端参数："+user);
       // User us=userDao.getUserByMassage("",user.getPassword());
        User us=userDao.getUserByMassage(user.getUsername(),user.getPassword());
        System.out.println("后端查询结果"+us);
        HashMap<String, Object> res=new HashMap<>();
        String res_json = null;
        if(us!=null)
        {
            code=20000;
            HashMap<String, Object> data = new HashMap<>();
            data.put("token",us.getId());
            res.put("data",data);
            System.out.println(res);
        }
        res.put("code",code);
        res_json=JSON.toJSONString(res);
       return  res_json;
   }
}
